using System;
using System.Data;

using SqlHelperForCry.Common;

namespace Torch.WL.Entity
{
    [Table("Tb_Sys_Roles", "RoleID", "Torch.WL.ConnectionString")]
	public class Tb_Sys_Roles : Info
	{
		#region SQL column name consts 
		public const string SQLCOL_ROLEID = "RoleID";
		public const string SQLCOL_ROLEGROUPID = "RoleGroupID";
		public const string SQLCOL_ROLENAME = "RoleName";
		public const string SQLCOL_ROLEDESCRIPTION = "RoleDescription";
		public const string SQLCOL_ROLEORDER = "RoleOrder";
		#endregion


		#region Contructors
		/// <summary>
		/// Construct empty entity
		/// </summary>
		public Tb_Sys_Roles () {}

		/// <summary>
		/// Construct entity by primary key, other fields will be assigned by 
		/// "Load" method.
		/// </summary>
		public Tb_Sys_Roles (int RoleID)
		{
			this.RoleID = RoleID;
		}
		#endregion

		public override void Init (DataRow row)
		{
			RoleID = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_ROLEID]);
			RoleGroupID = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_ROLEGROUPID]);
			RoleName = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_ROLENAME]);
			RoleDescription = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_ROLEDESCRIPTION]);
			RoleOrder = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_ROLEORDER]);
		}

		#region Properties 
		#region Property <int> RoleID
		[Property("RoleID", 4, SqlDbType.Int, true, true)]
		public int RoleID 
		{
			get { return _RoleID; }
			set { _RoleID = value; }
		}
		private int _RoleID = int.MinValue;
		#endregion

		#region Property <int> RoleGroupID
		[Property("RoleGroupID", 4, SqlDbType.Int, false, false)]
		public int RoleGroupID 
		{
			get { return _RoleGroupID; }
			set { _RoleGroupID = value; }
		}
		private int _RoleGroupID = int.MinValue;
		#endregion

		#region Property <string> RoleName
		[Property("RoleName", 60, SqlDbType.NVarChar, false, false)]
		public string RoleName 
		{
			get { return _RoleName; }
			set { _RoleName = value; }
		}
		private string _RoleName = null;
		#endregion

		#region Property <string> RoleDescription
		[Property("RoleDescription", 100, SqlDbType.NVarChar, false, false)]
		public string RoleDescription 
		{
			get { return _RoleDescription; }
			set { _RoleDescription = value; }
		}
		private string _RoleDescription = null;
		#endregion

		#region Property <int> RoleOrder
		[Property("RoleOrder", 4, SqlDbType.Int, false, false)]
		public int RoleOrder 
		{
			get { return _RoleOrder; }
			set { _RoleOrder = value; }
		}
		private int _RoleOrder = int.MinValue;
		#endregion
		#endregion


		public bool LoadByIdentity(int RoleID)
		{
			return DataAccess.SelectByIdentity(this, Convert.ToInt64(RoleID));
		}


		public bool DeleteByIdentity()
		{
			return DataAccess.DeleteByIdentity(this);
		}
	}
}
